<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <head>
        <title>Title</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.4.5/layui/css/layui.css" media="all">
        <script src="../../layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
    </head>
    <style>
        .wrap {
            width: 200px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }
    </style>
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<form class="layui-form" >

    <table class="layui-table">

        <thead>
        <tr>
            <th  width="40%">描述</th>
            <th  class="wrap">字段值</th>
            <th  width="40%">操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${pageUtil.list}" var="rl">
            <tr>
                <td>${rl.describe}</td>
                <td class="wrap"><div class="wrap" title="${rl.value}">${rl.value}</div></td>
                <td>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button type="button" class="layui-btn" onclick="updateInfo('${rl.element}','${rl.describe}');">修改</button>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div style="height:150px;"></div>
</form>
<script>
    function updateInfo(element,describe){
        var newValue=null;
        $.ajax({
            url:'/shop/showXiugai',
            type:'POST', //GET
            async:false,    //或false,是否异步
            data:{'element':element},
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(data){
                if(data.result){
                    newValue=data.data;
                }else{
                    layer.msg("保存失败");
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        });

        layui.use('layer',function(){
            var contentStr="<label class='layui-form-label'>"+describe+"</label>" +
                "<textarea id='myValue' rows='15' class='layui-textarea'>"+newValue+"</textarea>";
            //示范一个公告层
            layer.open({
                type: 1
                ,title: false //不显示标题栏
                ,closeBtn: false
                ,area: ['1500px','410px']
                ,shade: 0.8
                ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                ,btn: ['确认', '取消']
                ,btnAlign: 'c'
                ,moveType: 1 //拖拽模式，0或者1
                ,content: contentStr
                ,success: function(layero){
                }
                ,yes:function(index,layero){
                    newValue= layero.find('.layui-textarea').val();
                    send(element,newValue);
                    layer.close(index);
                }
                ,cancel:function(){
                    return;
                }
            });
        });
    }
    function send(element,newValue) {
        $.ajax({
            url: '/shop/xiugaicanshu',
            type: 'POST', //GET
            async: true,    //或false,是否异步
            data: {'element': element, 'value': newValue},
            timeout: 5000,    //超时时间
            dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend: function (xhr) {
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success: function (data) {
                console.log(data);
                if (data.code == '000000') {
                    window.location.reload();
                } else {
                    layer.msg("保存失败");
                }
            },
            error: function (xhr, textStatus) {
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete: function () {
                //console.log('结束')
            }
        });
    }
</script>
</body>
</html>
